
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>3.3 邮箱验证 · Laravel学习-从零开发论坛系统</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="kaleozhou">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="4.html" />
    
    
    <link rel="prev" href="2.html" />
    

    
        <link rel="shortcut icon" href='../book.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../book.ico' type="image/x-icon">
    
    
        <link rel="apple-touch-icon" href='../book.ico'>
    
    
        
        <link rel="apple-touch-icon" sizes="120x120" href="../book.ico">
        
        <link rel="apple-touch-icon" sizes="180x180" href="../book.ico">
        
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://www.kaleozhou.top" target="_blank" class="custom-link">我的博客</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    序言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter1/1.html">
            
                <a href="../chapter1/1.html">
            
                    
                    第一章 开发环境搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter2/readme.html">
            
                <a href="../chapter2/readme.html">
            
                    
                    第二章 创建应用及布局
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter2/1.html">
            
                <a href="../chapter2/1.html">
            
                    
                    2.1 创建应用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../chapter2/2.html">
            
                <a href="../chapter2/2.html">
            
                    
                    2.2 创建布局文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../chapter2/3.html">
            
                <a href="../chapter2/3.html">
            
                    
                    2.3 创建首页展示
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../chapter2/4.html">
            
                <a href="../chapter2/4.html">
            
                    
                    2.4 调整样式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="readme.html">
            
                <a href="readme.html">
            
                    
                    第三章 laravel组件的使用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="1.html">
            
                <a href="1.html">
            
                    
                    3.1 用户脚手架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="2.html">
            
                <a href="2.html">
            
                    
                    3.2 注册验证码
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.3" data-path="3.html">
            
                <a href="3.html">
            
                    
                    3.3 邮箱验证
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="4.html">
            
                <a href="4.html">
            
                    
                    3.4 密码重置
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../chapter4/readme.html">
            
                <a href="../chapter4/readme.html">
            
                    
                    第四章 基础功能开发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../chapter4/1.html">
            
                <a href="../chapter4/1.html">
            
                    
                    4.1 个人页面
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../chapter4/2.html">
            
                <a href="../chapter4/2.html">
            
                    
                    4.2 编辑个人资料
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../chapter4/3.html">
            
                <a href="../chapter4/3.html">
            
                    
                    4.3 显示个人资料
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../chapter4/4.html">
            
                <a href="../chapter4/4.html">
            
                    
                    4.4 上传头像
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../chapter5/readme.html">
            
                <a href="../chapter5/readme.html">
            
                    
                    第五章 帖子功能开发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../chapter5/1.html">
            
                <a href="../chapter5/1.html">
            
                    
                    5.1 帖子分类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../chapter5/2.html">
            
                <a href="../chapter5/2.html">
            
                    
                    5.2 代码生成器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../chapter5/3.html">
            
                <a href="../chapter5/3.html">
            
                    
                    5.3 生成话题骨架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../chapter5/4.html">
            
                <a href="../chapter5/4.html">
            
                    
                    5.4 假数据填充
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../chapter5/5.html">
            
                <a href="../chapter5/5.html">
            
                    
                    5.5 话题列表页面
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../chapter5/6.html">
            
                <a href="../chapter5/6.html">
            
                    
                    5.6 性能优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../chapter5/7.html">
            
                <a href="../chapter5/7.html">
            
                    
                    5.7 分类下的话题列表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../chapter5/8.html">
            
                <a href="../chapter5/8.html">
            
                    
                    5.8 话题排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../chapter5/9.html">
            
                <a href="../chapter5/9.html">
            
                    
                    5.9 用户发布的话题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../chapter6/readme.html">
            
                <a href="../chapter6/readme.html">
            
                    
                    第六章 话题开发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../chapter6/1.html">
            
                <a href="../chapter6/1.html">
            
                    
                    6.1 新建话题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../chapter6/2.html">
            
                <a href="../chapter6/2.html">
            
                    
                    6.2 编辑器优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../chapter6/3.html">
            
                <a href="../chapter6/3.html">
            
                    
                    6.3 上传图片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../chapter6/4.html">
            
                <a href="../chapter6/4.html">
            
                    
                    6.4 显示帖子
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../chapter6/5.html">
            
                <a href="../chapter6/5.html">
            
                    
                    6.5 XSS安全漏洞
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../chapter6/6.html">
            
                <a href="../chapter6/6.html">
            
                    
                    6.6 编辑帖子
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >3.3 邮箱验证</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#33-&#x90AE;&#x7BB1;&#x8BA4;&#x8BC1;"><b></b>3.3 &#x90AE;&#x7BB1;&#x8BA4;&#x8BC1;</a></li><ul><li><span class="title-icon "></span><a href="#&#x4FEE;&#x6539;&#x6A21;&#x578B;&#x5B58;&#x653E;&#x4F4D;&#x7F6E;"><b></b>&#x4FEE;&#x6539;&#x6A21;&#x578B;&#x5B58;&#x653E;&#x4F4D;&#x7F6E;</a></li><li><span class="title-icon "></span><a href="#&#x4FEE;&#x6539;user&#x6A21;&#x578B;"><b></b>&#x4FEE;&#x6539;User&#x6A21;&#x578B;</a></li><li><span class="title-icon "></span><a href="#&#x5F00;&#x59CB;&#x6D4B;&#x8BD5;"><b></b>&#x5F00;&#x59CB;&#x6D4B;&#x8BD5;</a></li><li><span class="title-icon "></span><a href="#&#x5F3A;&#x5236;&#x7528;&#x6237;&#x9A8C;&#x8BC1;"><b></b>&#x5F3A;&#x5236;&#x7528;&#x6237;&#x9A8C;&#x8BC1;</a></li><li><span class="title-icon "></span><a href="#laravel&#x4E8B;&#x4EF6;&#x7CFB;&#x7EDF;"><b></b>Laravel&#x4E8B;&#x4EF6;&#x7CFB;&#x7EDF;</a></li></ul></ul></div><a href="#33-&#x90AE;&#x7BB1;&#x8BA4;&#x8BC1;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="33-&#x90AE;&#x7BB1;&#x8BA4;&#x8BC1;"><a name="33-&#x90AE;&#x7BB1;&#x8BA4;&#x8BC1;" class="anchor-navigation-ex-anchor" href="#33-&#x90AE;&#x7BB1;&#x8BA4;&#x8BC1;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="33-&#x90AE;&#x7BB1;&#x8BA4;&#x8BC1;" class="plugin-anchor" href="#33-&#x90AE;&#x7BB1;&#x8BA4;&#x8BC1;"><i class="fa fa-link" aria-hidden="true"></i></a>3.3 &#x90AE;&#x7BB1;&#x8BA4;&#x8BC1;</h1>
<h2 id="&#x4FEE;&#x6539;&#x6A21;&#x578B;&#x5B58;&#x653E;&#x4F4D;&#x7F6E;"><a name="&#x4FEE;&#x6539;&#x6A21;&#x578B;&#x5B58;&#x653E;&#x4F4D;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#&#x4FEE;&#x6539;&#x6A21;&#x578B;&#x5B58;&#x653E;&#x4F4D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x4FEE;&#x6539;&#x6A21;&#x578B;&#x5B58;&#x653E;&#x4F4D;&#x7F6E;" class="plugin-anchor" href="#&#x4FEE;&#x6539;&#x6A21;&#x578B;&#x5B58;&#x653E;&#x4F4D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4FEE;&#x6539;&#x6A21;&#x578B;&#x5B58;&#x653E;&#x4F4D;&#x7F6E;</h2>
<p>Laravel&#x4E3A;&#x6211;&#x4EEC;&#x751F;&#x6210;&#x4E86;&#x7528;&#x6237;&#x6A21;&#x578B;&#x6587;&#x4EF6;app/User.php&#xFF0C;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;Laravel&#x4F1A;&#x5C06;&#x751F;&#x6210;&#x7684;&#x6A21;&#x578B;&#x6587;&#x4EF6;&#x653E;&#x5728;app&#x6587;&#x4EF6;&#x5939;&#x4E0B;&#x3002;&#x4E3A;&#x4E86;&#x9075;&#x5FAA;MVC&#x7684;&#x5F00;&#x53D1;&#x8303;&#x5F0F;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x7EDF;&#x4E00;&#x653E;&#x5728;app/Models&#x6587;&#x4EF6;&#x5939;&#x4E0B;&#x3002;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;app/Models&#x6587;&#x4EF6;&#x5939;&#xFF0C;&#x5E76;&#x5C06;User.php&#x6587;&#x4EF6;&#x653E;&#x7F6E;&#x5728;&#x5176;&#x4E2D;&#x3002;</p>
<pre><code>&#x279C; kaleo@zhou  ~/Code/kaleobbs git:(master) mkdir app/Models
&#x279C; kaleo@zhou  ~/Code/kaleobbs git:(master) mv app/User.php app/Models/User.php
</code></pre><p>&#x6267;&#x884C;&#x73A9;&#x8FD9;&#x4E00;&#x6B65;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x9700;&#x8981;&#x6267;&#x884C;&#x4E0B;&#x9762;&#x7684;&#x64CD;&#x4F5C;
1&#x3001; &#x4FEE;&#x6539;User.php&#x6587;&#x4EF6;&#xFF0C;&#x66F4;&#x6539;namespace&#x4E3A;&#x6211;&#x4EEC;&#x65B0;&#x521B;&#x5EFA;&#x7684;&#x6587;&#x4EF6;&#x5939;&#x8DEF;&#x5F84;
app/Models/User.php
2&#x3001;&#x4F7F;&#x7528;sublime&#x5168;&#x5C40;&#x66FF;&#x6362;App\User&#x4E3A;App\Models\User</p>
<h2 id="&#x4FEE;&#x6539;user&#x6A21;&#x578B;"><a name="&#x4FEE;&#x6539;user&#x6A21;&#x578B;" class="anchor-navigation-ex-anchor" href="#&#x4FEE;&#x6539;user&#x6A21;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x4FEE;&#x6539;user&#x6A21;&#x578B;" class="plugin-anchor" href="#&#x4FEE;&#x6539;user&#x6A21;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4FEE;&#x6539;User&#x6A21;&#x578B;</h2>
<p>&#x5C06;Laravel&#x81EA;&#x5E26;&#x7684;&#x90AE;&#x7BB1;&#x8BA4;&#x8BC1;&#x529F;&#x80FD;&#x96C6;&#x6210;&#x5230;&#x6211;&#x4EEC;&#x7684;&#x7A0B;&#x5E8F;&#x4E2D;
app/Models/User.php</p>
<pre><code>&lt;?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Auth\MustVerifyEmail as MustVerifyEmailTrait;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;

class User extends Authenticatable implements MustVerifyEmailContract
{
    use Notifiable, MustVerifyEmailTrait;

    protected $fillable = [
        &apos;name&apos;, &apos;email&apos;, &apos;password&apos;,
    ];

    protected $hidden = [
        &apos;password&apos;, &apos;remember_token&apos;,
    ];
}
</code></pre><h2 id="&#x5F00;&#x59CB;&#x6D4B;&#x8BD5;"><a name="&#x5F00;&#x59CB;&#x6D4B;&#x8BD5;" class="anchor-navigation-ex-anchor" href="#&#x5F00;&#x59CB;&#x6D4B;&#x8BD5;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x5F00;&#x59CB;&#x6D4B;&#x8BD5;" class="plugin-anchor" href="#&#x5F00;&#x59CB;&#x6D4B;&#x8BD5;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5F00;&#x59CB;&#x6D4B;&#x8BD5;</h2>
<p>&#x4FEE;&#x6539;.env&#x6587;&#x4EF6;&#xFF0C;&#x8BBE;&#x7F6E;</p>
<pre><code>MAIL_DRIVER=log
</code></pre><p>&#x8BB0;&#x5F97;&#x91CD;&#x542F;&#x865A;&#x62DF;&#x673A;&#xFF0C;&#x91CD;&#x65B0;&#x52A0;&#x8F7D;.env,&#x4E4B;&#x540E;&#x8BBF;&#x95EE;<a href="http://kaleobbs.test/register" target="_blank">http://kaleobbs.test/register</a>
<img src="http://images.kaleozhou.top/3.3-01.png" alt="3.3-01.png">
&#x67E5;&#x770B;&#x65E5;&#x5FD7;
<img src="http://images.kaleozhou.top/3.3-02.png" alt="3.3-02.png"></p>
<pre><code>[kaleobbs](http://kaleobbs.test)

# &#x60A8;&#x597D;&#xFF1A;

&#x8BF7;&#x70B9;&#x51FB;&#x4E0B;&#x9762;&#x6309;&#x94AE;&#x9A8C;&#x8BC1;&#x60A8;&#x7684; E-mail&#xFF1A;

&#x9A8C;&#x8BC1; E-mail: http://kaleobbs.test/email/verify/9?expires=1554598780&amp;signature=327bf9b69c8f5fe5de0a45c2810f6f465936feeae510c70530233846d3a0a229

&#x5982;&#x679C;&#x60A8;&#x672A;&#x6CE8;&#x518C;&#x5E10;&#x53F7;&#xFF0C;&#x8BF7;&#x5FFD;&#x7565;&#x6B64;&#x90AE;&#x4EF6;&#x3002;

&#x81F4;&#x656C;,kaleobbs

&#x5982;&#x679C;&#x60A8;&#x70B9;&#x51FB;&#x300C;&#x9A8C;&#x8BC1; E-mail&#x300D;&#x6309;&#x94AE;&#x65F6;&#x51FA;&#x73B0;&#x95EE;&#x9898;&#xFF0C;&#x8BF7;&#x590D;&#x5236;&#x4E0B;&#x65B9;&#x94FE;&#x63A5;&#x5230;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x5F00;&#x542F;&#xFF1A; [http://kaleobbs.test/email/verify/9?expires=1554598780&amp;signature=327bf9b69c8f5fe5de0a45c2810f6f465936feeae510c70530233846d3a0a229](http://kaleobbs.test/email/verify/9?expires=1554598780&amp;signature=327bf9b69c8f5fe5de0a45c2810f6f465936feeae510c70530233846d3a0a229)

&#xA9; 2019 kaleobbs. &#x7248;&#x672C;&#x6240;&#x6709;&#x3002;
</code></pre><p>&#x8FD9;&#x91CC;&#x4E00;&#x4F1A;&#x518D;&#x8BBF;&#x95EE;&#x8FDE;&#x63A5;</p>
<h2 id="&#x5F3A;&#x5236;&#x7528;&#x6237;&#x9A8C;&#x8BC1;"><a name="&#x5F3A;&#x5236;&#x7528;&#x6237;&#x9A8C;&#x8BC1;" class="anchor-navigation-ex-anchor" href="#&#x5F3A;&#x5236;&#x7528;&#x6237;&#x9A8C;&#x8BC1;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x5F3A;&#x5236;&#x7528;&#x6237;&#x9A8C;&#x8BC1;" class="plugin-anchor" href="#&#x5F3A;&#x5236;&#x7528;&#x6237;&#x9A8C;&#x8BC1;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5F3A;&#x5236;&#x7528;&#x6237;&#x9A8C;&#x8BC1;</h2>
<p>&#x6211;&#x4EEC;&#x5E0C;&#x671B;&#x7528;&#x6237;&#x9A8C;&#x8BC1;&#x4E4B;&#x540E;&#x624D;&#x80FD;&#x4F7F;&#x7528;&#x7F51;&#x7AD9;&#xFF0C;&#x9996;&#x5148;&#x6211;&#x4EEC;&#x9A8C;&#x8BC1;&#x4E00;&#x4E0B;&#x7528;&#x6237;&#x5F53;&#x524D;&#x662F;&#x5426;&#x9A8C;&#x8BC1;&#xFF0C;&#x505A;&#x4E2A;&#x6D4B;&#x8BD5;&#xFF1A;
app/Http/Controllers/PagesController.php</p>
<pre><code>&lt;?php

namespace app\http\controllers;

use illuminate\http\request;

class pagescontroller extends controller
{
    //
    //&#x9996;&#x9875;&#x7684;&#x65B9;&#x6CD5;
    public function root()
    {
        dd(\auth::user()-&gt;hasverifiedemail());
        return view(&apos;pages.root&apos;);
    }

}
</code></pre><p>&#x8BBF;&#x95EE;&#x9996;&#x9875;
<img src="http://images.kaleozhou.top/3.3-03.png" alt="3.3-03.png">
&#x51FA;&#x73B0;&#x9519;&#x8BEF;&#xFF0C;&#x548C;&#x6211;&#x4EEC;&#x60F3;&#x7684;&#x4E00;&#x6837;
&#x68C0;&#x51FA;app/Http/Controllers/PagesController.php</p>
<pre><code>&#x279C; kaleo@zhou  ~/Code/kaleobbs git:(master) &#x2717; git checkout app/Http/Controllers/PagesController.php
</code></pre><p>&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x4F7F;&#x7528;Laravel&#x4E2D;&#x95F4;&#x4EF6;&#x6765;&#x8FC7;&#x6EE4;&#x7528;&#x6237;&#x6240;&#x6709;&#x8BF7;&#x6C42;&#xFF0C;&#x5982;&#x679C;&#x7528;&#x6237;&#x672A;&#x8BA4;&#x8BC1;&#x7684;&#x8BDD;&#x5C31;&#x8DF3;&#x8F6C;&#x5230;&#x90AE;&#x4EF6;&#x8BA4;&#x8BC1;&#x63D0;&#x9192;&#x9875;&#x9762;&#x4E2D;&#xFF0C;&#x4E2D;&#x95F4;&#x4EF6;&#x662F;Laravel&#x4E2D;&#x5F00;&#x53D1;&#x7ECF;&#x5E38;&#x4F7F;&#x7528;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x6B64;&#x5904;&#x6211;&#x4EEC;&#x5148;&#x4F7F;&#x7528;&#xFF0C;&#x540E;&#x9762;&#x4F1A;&#x4E13;&#x95E8;&#x8BB2;&#x89E3;&#x3002;
&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4E00;&#x4E0B;&#x547D;&#x4EE4;&#x6765;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;&#x4E2D;&#x95F4;&#x4EF6;:</p>
<pre><code>vagrant@homestead:~/Code/kaleobbs$ php artisan make:middleware EnsureEmailIsVerified
</code></pre><p>&#x6253;&#x5F00;&#x751F;&#x6210;&#x7684;&#x6587;&#x4EF6;&#x5E76;&#x5E26;&#x5165;&#x4E00;&#x4E0B;&#x5185;&#x5BB9;
app/Http/Middleware/EnsureEmailIsVerifie</p>
<pre><code>&lt;?php

namespace App\Http\Middleware;

use Closure;

class EnsureEmailIsVerified
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //&#x4E09;&#x4E2A;&#x5224;&#x65AD;:
        //1.&#x5982;&#x679C;&#x7528;&#x6237;&#x5DF2;&#x7ECF;&#x767B;&#x5F55;
        //2.&#x5E76;&#x4E14;&#x8FD8;&#x672A;&#x8BA4;&#x8BC1;Email
        //3.&#x5E76;&#x4E14;&#x8BBF;&#x95EE;&#x7684;&#x4E0D;&#x662F;email&#x9A8C;&#x8BC1;&#x76F8;&#x5173;&#x7684;URL&#x6216;&#x8005;&#x9000;&#x51FA;&#x7684;URL&#x3002;
        if($request-&gt;user()&amp;&amp;
            ! $request-&gt;user()-&gt;hasVerifiedEmail()&amp;&amp;
            ! $request-&gt;is(&apos;email/*&apos;,&apos;logout&apos;)){
            //&#x6839;&#x636E;&#x5BA2;&#x6237;&#x7AEF;&#x8FD4;&#x56DE;&#x5BF9;&#x5E94;&#x7684;&#x5185;&#x5BB9;
            return $request-&gt;expectsJson()
                ? abort(403,&apos;Your email address is not verified.&apos;)
                : redirect()-&gt;route(&apos;verification.notice&apos;);
        }
        return $next($request);
    }
}
</code></pre><p>&#x63A5;&#x4E0B;&#x6765;&#x6CE8;&#x518C;&#x4E2D;&#x95F4;&#x4EF6;&#x3002;&#x6CE8;&#x518C;&#x7684;&#x5B9E;&#x9645;&#x786E;&#x4FDD;&#x5728;StartSession&#x540E;&#x9762;&#x5373;&#x53EF;:
app/Http/Kernel.php</p>
<pre><code>&lt;?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    /**
     * The application&apos;s global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array
     */
    protected $middleware = [
        \App\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
        \App\Http\Middleware\TrustProxies::class,
    ];

    /**
     * The application&apos;s route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        &apos;web&apos; =&gt; [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \App\Http\Middleware\EnsureEmailIsVerified::class, //&#x53EA;&#x9700;&#x8981;&#x6DFB;&#x52A0;&#x8FD9;&#x4E00;&#x884C;
        ],

        &apos;api&apos; =&gt; [
            &apos;throttle:60,1&apos;,
            &apos;bindings&apos;,
        ],
    ];

    /**
     * The application&apos;s route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        &apos;auth&apos; =&gt; \App\Http\Middleware\Authenticate::class,
        &apos;auth.basic&apos; =&gt; \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        &apos;bindings&apos; =&gt; \Illuminate\Routing\Middleware\SubstituteBindings::class,
        &apos;cache.headers&apos; =&gt; \Illuminate\Http\Middleware\SetCacheHeaders::class,
        &apos;can&apos; =&gt; \Illuminate\Auth\Middleware\Authorize::class,
        &apos;guest&apos; =&gt; \App\Http\Middleware\RedirectIfAuthenticated::class,
        &apos;signed&apos; =&gt; \Illuminate\Routing\Middleware\ValidateSignature::class,
        &apos;throttle&apos; =&gt; \Illuminate\Routing\Middleware\ThrottleRequests::class,
        &apos;verified&apos; =&gt; \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
    ];

    /**
     * The priority-sorted list of middleware.
     *
     * This forces non-global middleware to always be in the given order.
     *
     * @var array
     */
    protected $middlewarePriority = [
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\Authenticate::class,
        \Illuminate\Session\Middleware\AuthenticateSession::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
        \Illuminate\Auth\Middleware\Authorize::class,
    ];
}
</code></pre><p>&#x70B9;&#x51FB;&#x5237;&#x65B0;&#x4E4B;&#x540E;&#x7684;&#x7ED3;&#x679C;
<img src="http://images.kaleozhou.top/3.3-04.png" alt="3.3-04.png"></p>
<h2 id="laravel&#x4E8B;&#x4EF6;&#x7CFB;&#x7EDF;"><a name="laravel&#x4E8B;&#x4EF6;&#x7CFB;&#x7EDF;" class="anchor-navigation-ex-anchor" href="#laravel&#x4E8B;&#x4EF6;&#x7CFB;&#x7EDF;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="laravel&#x4E8B;&#x4EF6;&#x7CFB;&#x7EDF;" class="plugin-anchor" href="#laravel&#x4E8B;&#x4EF6;&#x7CFB;&#x7EDF;"><i class="fa fa-link" aria-hidden="true"></i></a>Laravel&#x4E8B;&#x4EF6;&#x7CFB;&#x7EDF;</h2>
<p>Laravel &#x4E8B;&#x4EF6;&#x662F;&#x4E00;&#x5957;&#x7B80;&#x5355;&#x7684;&#x89C2;&#x5BDF;&#x8005;&#x5B9E;&#x73B0;&#xFF0C;&#x80FD;&#x591F;&#x8BA2;&#x9605;&#x548C;&#x76D1;&#x542C;&#x5E94;&#x7528;&#x4E2D;&#x53D1;&#x751F;&#x7684;&#x5404;&#x79CD;&#x4E8B;&#x4EF6;&#x3002;&#x4E8B;&#x4EF6;&#x7CFB;&#x7EDF;&#x4E3A;&#x5E94;&#x7528;&#x5404;&#x4E2A;&#x65B9;&#x9762;&#x7684;&#x89E3;&#x8026;&#x63D0;&#x4F9B;&#x4E86;
&#x975E;&#x5E38;&#x68D2;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#xFF0C;&#x56E0;&#x4E3A;&#x5355;&#x4E2A;&#x4E8B;&#x4EF6;&#x53EF;&#x4EE5;&#x62E5;&#x6709;&#x591A;&#x4E2A;&#x4E92;&#x8865;&#x4F9D;&#x8D56;&#x989D;&#x76D1;&#x542C;&#x5668;&#x3002;
&#x5728;&#x6211;&#x4EEC;&#x8FD9;&#x4E2A;&#x573A;&#x666F;&#x4E2D;&#xFF0C;&#x7528;&#x6237;&#x8BA4;&#x8BC1;&#x540E;&#x89E6;&#x53D1;&#x4E86;Verified&#x4E8B;&#x4EF6;&#xFF0C;&#x6211;&#x4EEC;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x76D1;&#x542C;&#x5373;&#x53EF;&#x52A0;&#x5165;&#x6211;&#x4EEC;&#x60F3;&#x8981;&#x7684;&#x903B;&#x8F91;&#x3002;
app/Providers/EventServiceProvider.php</p>
<pre><code>&lt;?php

namespace App\Providers;

use Illuminate\Support\Facades\Event;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        Registered::class =&gt; [
            SendEmailVerificationNotification::class,
        ],
        \Illuminate\Auth\Events\Verified::class =&gt; [
            \App\Listeners\EmailVerified::class,
        ],
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

        //
    }
}
</code></pre><p>&#x6267;&#x884C;&#x4E00;&#x4E0B;&#x547D;&#x4EE4;&#x751F;&#x6210;&#x8FD9;&#x4E2A;&#x76D1;&#x542C;&#x5668;:</p>
<pre><code>vagrant@homestead:~/Code/kaleobbs$ php artisan event:generate
Events and listeners generated successfully!
</code></pre><p>&#x4EE5;&#x4E0A;&#x547D;&#x4EE4;&#x4F1A;&#x4E3A;&#x6211;&#x4EEC;&#x751F;&#x6210;app/Listeners/EmailVerified.php,&#x7A0D;&#x4F5C;&#x4FEE;&#x6539;:</p>
<pre><code>&lt;?php

namespace App\Listeners;

use Illuminate\Auth\Events\Verified;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class EmailVerified
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  Verified  $event
     * @return void
     */
    public function handle(Verified $event)
    {
        //&#x4F1A;&#x8BDD;&#x91CC;&#x95EA;&#x5B58;&#x8BA4;&#x8BC1;&#x6210;&#x529F;&#x540E;&#x7684;&#x6D88;&#x606F;&#x63D0;&#x9192;
        session()-&gt;flash(&apos;success&apos;,&apos;&#x90AE;&#x7BB1;&#x9A8C;&#x8BC1;&#x6210;&#x529F;&#xFF01;&apos;);
    }
}
</code></pre><p>&#x6D4B;&#x8BD5;&#x518D;&#x6B21;&#x53D1;&#x9001;&#x90AE;&#x4EF6;&#x9A8C;&#x8BC1;
<img src="http://images.kaleozhou.top/3.3-05.png" alt="3.3-05.png">
&#x9A8C;&#x8BC1;&#x5B8C;&#x6210;&#x4E4B;&#x540E;
<img src="http://images.kaleozhou.top/3.3-06.png" alt="3.3-06.png"></p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; kaleozhou 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2019-05-20 16:24:22
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="2.html" class="navigation navigation-prev " aria-label="Previous page: 3.2 注册验证码">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="4.html" class="navigation navigation-next " aria-label="Next page: 3.4 密码重置">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"3.3 邮箱验证","level":"1.4.3","depth":2,"next":{"title":"3.4 密码重置","level":"1.4.4","depth":2,"path":"chapter3/4.md","ref":"chapter3/4.md","articles":[]},"previous":{"title":"3.2 注册验证码","level":"1.4.2","depth":2,"path":"chapter3/2.md","ref":"chapter3/2.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","splitter","expandable-chapters-small","anchors","donate","sharing-plus","anchor-navigation-ex","tbfed-pagefooter","favicon"],"styles":{"website":"./styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy kaleozhou 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"github":{"url":"https://gitee.com/kaleozhou"},"splitter":{},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"http://images.kaleozhou.top/zanshang.png","alipayText":" ","button":"赞赏","title":"","wechat":"","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":false},"favicon":{"shortcut":"./book.ico","bookmark":"./book.ico","appleTouch":"./book.ico","appleTouchMore":{"120x120":"./book.ico","180x180":"./book.ico"}},"github-buttons":{"buttons":[{"user":"kaleozhou","repo":"guanwang","type":"star","size":"small","count":true}]},"expandable-chapters-small":{},"sharing":{"qq":true,"all":["weibo","qq","qzone"],"douban":true,"facebook":false,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":true,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{}},"theme":"default","author":"kaleozhou","pdf":{"pageBreaksBefore":"/","paperSize":"a4","margin":{"right":30,"left":30,"top":30,"bottom":50},"fontSize":18,"pageSize":"a4","fontFamily":"Arial","doc":true,"chapterMark":"pagebreak","pageNumbers":true},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Laravel学习-从零开发论坛系统","language":"zh-hans","links":{"sidebar":{"我的博客":"http://www.kaleozhou.top"}},"gitbook":"3.2.3","description":"laravel框架开发论坛系统"},"file":{"path":"chapter3/3.md","mtime":"2019-05-20T08:24:22.900Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-05-25T02:56:39.861Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

